import type * as Store from './type'
import http from '@/utils/http'

const BASE_URL = '/system/city'

export interface SystemCityPageQuery extends Store.SystemCityQuery, PageQuery {}

/** @desc 查询城市列表 */
export function listSystemCity(query: SystemCityPageQuery) {
  return http.get<PageRes<Store.SystemCityResp[]>>(`${BASE_URL}`, query)
}

/** @desc 查询城市详情 */
export function getSystemCity(id: string) {
  return http.get<Store.SystemCityDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 修改城市 */
export function updateSystemCity(data: any, id: string) {
  return http.patch(`${BASE_URL}/${id}/update`, data)
}

/** @desc 修改城市状态 */
export function updateSystemCityStatus(data: any, id: string) {
  return http.patch(`${BASE_URL}/${id}/update/status`, data)
}

/** @desc 城市详情 */
export function getSystemCityInfo(id: string) {
  return http.get(`${BASE_URL}/${id}/info`)
}

/** @desc 获取tree结构的列表 */
export function getSystemCityTree() {
  return http.get(`${BASE_URL}/list/tree`)
}

/** @desc 获取tree结构的父列表 */
export function getSystemCityTreeTop() {
  return http.get(`${BASE_URL}/list/tree/top`)
}

/** @desc 获取tree结构的子列表 */
export function getSystemCityTreeChild(id: number) {
  return http.get(`${BASE_URL}/${id}/list/tree/child`)
}

/** @desc 获取顶层节点下所有的子节点 */
export function getAllDescendants(id: number) {
  return http.get(`${BASE_URL}/${id}/list/tree/descendants`)
}

/** @desc 导出城市 */
export function exportSystemCity(query: Store.SystemCityQuery) {
  return http.download<any>(`${BASE_URL}/export`, query)
}
